<?php
namespace app\admin\controller;

use think\Controller;
use app\common\service\Upload as UploadService;

class Upload extends Controller
{
    /**
     * 上传图片
     * @param file $file 图片文件
     * @return json
     */
    public function image()
    {
        $file = $this->request->file('file');
        if (!$file) {
            return json(['code' => 0, 'msg' => '请选择文件']);
        }

        $upload = new UploadService();
        $result = $upload->image($file);

        if ($result['code'] == 1) {
            return json(['code' => 1, 'msg' => '上传成功', 'data' => $result['data']]);
        }
        return json(['code' => 0, 'msg' => $result['msg']]);
    }

    /**
     * 上传视频
     * @param file $file 视频文件
     * @return json
     */
    public function video()
    {
        $file = $this->request->file('file');
        if (!$file) {
            return json(['code' => 0, 'msg' => '请选择文件']);
        }

        $upload = new UploadService();
        $result = $upload->video($file);

        if ($result['code'] == 1) {
            return json(['code' => 1, 'msg' => '上传成功', 'data' => $result['data']]);
        }
        return json(['code' => 0, 'msg' => $result['msg']]);
    }
} 